/**
 * 查询指定分诊台对应的候诊病人列表
 */

//成都页面 候诊大厅

//获取数据；
function getHouzhenData(){
	var params = {};
    params.ID1 = "10000028";//查询候诊区每个医生对应的三个候诊病人
    params.ID2 = "10000029";//查询候诊区每个医生对应的当前接诊病人
    params.ID3 = "10000030";//查询候诊区当前有候诊病人货真接诊病人的医生
    params.tpl = "chengdu.html";
    getData(params);
}
function getData(params){
    var url =  rootUrl+"/clidoctor/selectDataByScriptId";
    var para1 = {},para2={},para3={};
    var paramStr = {};
    paramStr.triage_id = triage_id;
    para1.paramStr = JSON.stringify(paramStr);
    para2.paramStr = JSON.stringify(paramStr);
    para3.paramStr = JSON.stringify(paramStr);
    para1.ID = params.ID1;
    para2.ID = params.ID2;
    para3.ID = params.ID3;
    $.when(
        $.get(url,para1),
        $.get(url,para2),
        $.get(url,para3)
    ).done(function(data1,data2,data3){
        debugger;
        var obj = {};
        obj.list1 = data1[0].list;  //医生及所在的诊室
        obj.list2 = data2[0].list;  //正在就诊的病人
        obj.list3 = data3[0].list;  //等待就诊的病人
        obj.tpl = params.tpl;
        assembleDatagram(obj);

    })
}

//组装数据
function assembleDatagram(obj){
	var list1  = obj.list1,
	list2  = obj.list2, 
	list3  = obj.list3;
	var resultArr = [];
	//第三个与第二个，组装医生诊室和正在就诊的病人
	for(var i=0;i<list3.length;i++){
		var nowpatient = [];
		for(var j=0;j<list2.length;j++){
			if(list2[j].bce03a==list3[i].bce03a){
				nowpatient.push(list2[j].vaa05);
			}
		}
		nowpatient = nowpatient.join(",");
		list3[i].nowpatient = nowpatient;
		
		//resultArr.push(list3[i]);
	}
	//第三个数据和第一个数据匹配，组长等待就诊的病人和医生
	for(var i=0;i<list3.length;i++){
		var waitpatient = [];
		for(var j=0;j<list1.length;j++){
			if(list1[j].bce03a==list3[i].bce03a){
				waitpatient.push(list1[j].vaa05);
			}
		}
		waitpatient = waitpatient.join(",");
		list3[i].waitpatient = waitpatient;
		resultArr.push(list3[i]);
	}
	debugger;
    loadPage(resultArr,obj.tpl);
	
}
function loadPage(resultArr,tpl){
    laytplUrl("./成都中医大银海眼科医院/showTpl/"+tpl, resultArr, function(data, html)
    {
        $("body").html(html);
        //设置宽度
        setTimeout(function(){
            setTheadWidth();
            _InitScroll("A1", "A2", 19*20, 3000);

        },200)
    })
}
function setTheadWidth(){
	var all_td = $("#A2").find("table tr:eq(0)").find("td");
	$(all_td).each(function(i,ele){
		var tdwidht = $(ele).width()!=0?$(ele).width():"120px";
		$("#imgtable_thead").find(".td"+(i+2)).css("width",tdwidht);
	})
}
function _InitScroll(_S1, _S2, _H, _T) {
    document.getElementById(_S1).style.cssText ="height:"+_H +"px";
    return "var marqueesHeight" + _S1 + "=" + _H + ";var stopscroll" + _S1 + "=false;var scrollElem" + _S1 + "=document.getElementById('" + _S1 + "');with(scrollElem" + _S1 + "){style.height=marqueesHeight" + _S1 + ";style.overflow='hidden';noWrap=true;}scrollElem" + _S1 + ".onmouseover=new Function('stopscroll" + _S1 + "=true');scrollElem" + _S1 + ".onmouseout=new Function('stopscroll" + _S1 + "=false');var preTop" + _S1 + "=0; var currentTop" + _S1 + "=0; var stoptime" + _S1 + "=0;var leftElem" + _S2 + "=document.getElementById('" + _S2 + "');scrollElem" + _S1 + ".appendChild(leftElem" + _S2 + ".cloneNode(true));setTimeout('init_srolltext" + _S1 + "()'," + _T + ");function init_srolltext" + _S1 + "(){scrollElem" + _S1 + ".scrollTop=0;setInterval('scrollUp" + _S1 + "()',50);}function scrollUp" + _S1 + "(){if(stopscroll" + _S1 + "){return;}currentTop" + _S1 + "+=1;if(currentTop" + _S1 + "==(marqueesHeight" + _S1 + "+1)) {stoptime" + _S1 + "+=1;currentTop" + _S1 + "-=1;if(stoptime" + _S1 + "==" + _T / 50 + ") {currentTop" + _S1 + "=0;stoptime" + _S1 + "=0;}}else{preTop" + _S1 + "=scrollElem" + _S1 + ".scrollTop;scrollElem" + _S1 + ".scrollTop +=1;if(preTop" + _S1 + "==scrollElem" + _S1 + ".scrollTop){scrollElem" + _S1 + ".scrollTop=0;scrollElem" + _S1 + ".scrollTop +=1;}}}";
}


//成都页面2 大厅

function getDatingData(){
    var params = {};
    params.ID1 = "10000032";//查询全院每个医生对应的三个候诊病人
    params.ID2 = "10000033";//查询全院每个医生当前的接诊诊病人
    params.ID3 = "10000034";//查询全院当前有候诊病人或者接诊病人的医生集合
    params.tpl = "chengdu.html";
    getData(params);
}

//成都医生诊室页面
function getYishengZhenshiData(){
    var url =  rootUrl+"/clidoctor/selectDataByScriptId";
    var para = {};
    var paramStr = {};
    paramStr.bas01 = bas01;
    para.paramStr = JSON.stringify(paramStr);
    para.ID = "10000031";
  //查询医生信息
    var para1 = {};
    var paramStr1 = {};
    paramStr1.bas01 = bas01;
    para1.paramStr = JSON.stringify(paramStr1);
    para1.ID = "10000037";
    var para2 = {};
    var paramStr2 = {};
    paramStr2.bas01 = bas01;
    para2.paramStr = JSON.stringify(paramStr2);
    para2.ID = "10000038";
    $.when(
        $.get(url,para),  //病人信息
        $.get(url,para1), //医生信息
        $.get(url,para2)
    ).done(function(data,data1,data2){
        debugger;
        var map = {};
        map.list = data[0].list;
        var data1 = data1[0].list[0];
        map.bas02 = data2[0].list[0].bas02;
        map.bac02 = centerRUI1+"/imgUpload/"+data1.bac02;
        map.bce39 = data1.bce39;
        map.bce03 = data1.bce03;
        map.abi02 = data1.abi02;
        var tpl = "yisheng_zhenshi.html";
        loadPage(map,tpl);

    })
}




